package liumengbaio.lolzhangyoubao.Activity.Activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.util.ArrayList;
import java.util.List;

import liumengbaio.lolzhangyoubao.Activity.Adapter.ViewPagerAdapter;
import liumengbaio.lolzhangyoubao.Activity.Fragment.MyHistoryFragment;
import liumengbaio.lolzhangyoubao.Activity.InFo.BindRoleInfo;
import liumengbaio.lolzhangyoubao.R;

public class SelectHistoryActivity extends AppCompatActivity {
    private TabLayout histrory_tablayout;
    private ViewPager history_viewPager;
    private List<Fragment> lists;
    private List<String> tabNames;
    private ViewPagerAdapter adapter;
    private MyHistoryFragment myHistoryFragment_one,myHistoryFragment_two,myHistoryFragment_three;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_select_history);
        EventBus.getDefault().register(SelectHistoryActivity.this);
        initView();
    }

    private void initView() {
        histrory_tablayout= (TabLayout) findViewById(R.id.histrory_tablayout);
        history_viewPager= (ViewPager) findViewById(R.id.history_viewPager);
        tabNames=new ArrayList<>();
        myHistoryFragment_one=new MyHistoryFragment();
        myHistoryFragment_two=new MyHistoryFragment();
        myHistoryFragment_three=new MyHistoryFragment();
        lists=new ArrayList<>();
        tabNames.add("我的战绩");
        tabNames.add("对阵查询");
        tabNames.add("我的关注");
        lists.add(myHistoryFragment_one);
        lists.add(myHistoryFragment_two);
        lists.add(myHistoryFragment_three);
        adapter=new ViewPagerAdapter(getSupportFragmentManager(),tabNames,lists);
        history_viewPager.setAdapter(adapter);
        histrory_tablayout.setupWithViewPager(history_viewPager);
        findViewById(R.id.edit_head_left_title).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        findViewById(R.id.edit_right_title).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent_edit_head_title=new Intent(SelectHistoryActivity.this,BindRoleActivity.class);
                startActivity(intent_edit_head_title);
            }
        });
    }
    @Subscribe(threadMode= ThreadMode.MAIN)
    public void onEventMainThread(BindRoleInfo event) {
        String parmas_name=event.getName();
        String parmas_id=event.getArea();
        Bundle bundle=new Bundle();
        bundle.putString("parmas_name",parmas_name);
        bundle.putString("parmas_id",parmas_id);
        Log.i("221",parmas_id);
        Log.i("221",parmas_name);
    }
}
